package com.sdrongyou.tms.controller;

import com.alibaba.fastjson2.JSONObject;
import com.sdrongyou.tms.dto.CarDO;
import com.sdrongyou.tms.dto.CarVO;
import com.sdrongyou.tms.service.CarIService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车辆管理Controller
 */
@RestController
@RequestMapping(value = "/api/tms/car")
public class CarController {

    @Resource
    private CarIService carIService;

    /**
     * 分页查询
     */
    @RequestMapping(value = "/queryCarDataPageList", method = RequestMethod.GET)
    public List<CarVO> queryCarDataPageList(CarDO carDO) {
        return carIService.queryCarDataPageList(carDO);
    }

    /**
     * 新增车辆信息
     */
    @RequestMapping(value = "/saveCarInfo", method = RequestMethod.POST)
    public JSONObject saveCarInfo(@RequestBody CarDO carDO) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", carIService.saveCarInfo(carDO));
        return jsonObject;
    }

    /**
     * 更新车辆信息
     */
    @RequestMapping(value = "/updateCarInfo", method = RequestMethod.POST)
    public JSONObject updateCarInfo(@RequestBody CarDO carDO) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", carIService.updateCarInfo(carDO));
        return jsonObject;
    }

    /**
     * 删除车辆信息
     */
    @DeleteMapping(value = "/deleteCarInfo")
    public JSONObject deleteCarInfo(Long id) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", carIService.deleteCarInfo(id));
        return jsonObject;
    }

    /**
     * 批量删除车辆
     */
    @PostMapping(value = "/batchDeleteCarInfo")
    public JSONObject batchDeleteCarInfo(@RequestBody List<Long> ids) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", carIService.batchDeleteCarInfo(ids));
        return jsonObject;
    }

    /**
     * 查询单条车辆信息
     */
    @RequestMapping(value = "/queryCarById", method = RequestMethod.GET)
    public CarVO queryCarById(Long id) {
        return carIService.queryCarById(id);
    }


}
